PTPObject = {
	shuffle: function(o){ //v1.0
		for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
		return o;
	}
};

function compareDates(a, b) {
	try {		
		var dateA = new Date();
		dateA.setISO8601(a.media$group.yt$uploaded.$t);
		
		var dateB = new Date();
		dateB.setISO8601(b.media$group.yt$uploaded.$t);
		
		return dateB - dateA;
	} catch (ex) {
		//console.log(ex);
		//console.log("a= "+a.title.$t);
		//console.log("b= "+b.title.$t);
		return false;
	}
} 


function relative_time(C){	
	var A=Date.parse(C);
	var D=new Date();
	var E=parseInt((D.getTime()-A)/1000);
	E=E+(D.getTimezoneOffset());
	if(E<60)
		{ return "less than a minute ago" }
	else
		{ if (E<120) 
			{ return "about a minute ago" }
		else
			{
				if (E<(60*60)) {
					return (parseInt(E/60)).toString()+" minutes ago"}
				else {
					if(E<(120*60)) {
						return "about an hour ago"
					}
					else {
						if(E<(24*60*60)) {
							return "about "+(parseInt(E/3600)).toString()+" hours ago"
						}
						else {
							if(E<(48*60*60))
								{return"1 day ago"}
							else{return(parseInt(E/86400)).toString()+" days ago"}
						}
					}
				}
			}
		}
}

Array.prototype.last = function() {
	return this[(this.length-1)];
	
}


Date.prototype.setISO8601 = function (string) {
    var regexp = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})" +
        "(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?" +
        "(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?";
    var d = string.match(new RegExp(regexp));

    var offset = 0;
    var date = new Date(d[1], 0, 1);

    if (d[3]) { date.setMonth(d[3] - 1); }
    if (d[5]) { date.setDate(d[5]); }
    if (d[7]) { date.setHours(d[7]); }
    if (d[8]) { date.setMinutes(d[8]); }
    if (d[10]) { date.setSeconds(d[10]); }
    if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); }
    if (d[14]) {
        offset = (Number(d[16]) * 60) + Number(d[17]);
        offset *= ((d[15] == '-') ? 1 : -1);
    }

    offset -= date.getTimezoneOffset();
    var time = (Number(date) + (offset * 60 * 1000));
    this.setTime(Number(time));
}


KEYWORD = {
	//needle: new RegExp(needle,"g"),
}

KEYWORD.setNeedle = function(newNeedle) {
	this.needle = new RegExp(newNeedle,"gi");	
}

KEYWORD.getNeedle = function() {
	return this.needle;	
}